package com.seagull.sb.dao.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.seagull.sb.dao.OrganizationDAO;
import com.seagull.sb.domain.Division;
import com.seagull.sb.domain.Organization;
import com.seagull.sb.domain.Subject;
import com.seagull.sb.domain.Teacher;
import com.seagull.sb.util.SBRequestContext;

public class OrganizationDAOImpl extends BaseDAO implements OrganizationDAO {
	
	@Override
	public List<Teacher> getTeachers(SBRequestContext rc) throws Exception {
		Map<String,Object> qmap = new HashMap<String, Object>();
		
		qmap.put("org_id", new Long(rc.getOrgId()));
//		if(rc.getClassId()>0){
//			qmap.put("class_id", new Long(rc.getClassId()));
//		}
		Object result = sqlMap.queryForList("organizationDB.getTeachers",qmap);
		if(result instanceof List){
			return (List<Teacher>)result;
		}
		return Collections.EMPTY_LIST;
	}

	@Override
	public List<Division> getDivisions(SBRequestContext rc) throws Exception {
		Map<String,Object> qmap = new HashMap<String, Object>();
		qmap.put("org_id", new Long(rc.getOrgId()));
		
		Object result = sqlMap.queryForList("organizationDB.getDivisions",qmap);
		if(result instanceof List){
			return (List<Division>)result;
		}
		return Collections.EMPTY_LIST;
	}

	@Override
	public Organization getOrganization(SBRequestContext rc) throws Exception {
		Map<String,Object> qmap = new HashMap<String, Object>();
		
		qmap.put("org_id", new Long(rc.getOrgId()));
		Object result = sqlMap.queryForObject("organizationDB.getOrganization",qmap);
		if(result instanceof Organization){
			return (Organization)result;
		}
		throw new Exception("Organization not found.");
	}

	@Override
	public List<Subject> getSubjects(SBRequestContext rc) throws Exception {
		Map<String,Object> qmap = new HashMap<String, Object>();
		qmap.put("org_id", new Long(rc.getOrgId()));
		
		Object result = sqlMap.queryForList("organizationDB.getSubjects",qmap);
		if(result instanceof List){
			return (List<Subject>)result;
		}
		return Collections.EMPTY_LIST;		
	}

}
